package cn.liuweiwei.service.impl;

import cn.liuweiwei.domain.Resource;
import cn.liuweiwei.mapper.ResourceMapper;
import cn.liuweiwei.service.ResourceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public PageInfo<Resource> findResources(String page, String limit) {
        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
        return new PageInfo<>(resourceMapper.findAll());
    }

    @Override
    public void deleteResource(String id) {
        resourceMapper.delete(id);
    }

    @Override
    public void updateResource(Resource resource) {
        resourceMapper.update(resource);
    }

    @Override
    public void insertResource(Resource resource) {
        resourceMapper.insert(resource);
    }

    @Override
    public List<Resource> findResources(String title) {
        return resourceMapper.findByTitle(title);
    }

}
